﻿/****************************************************
 * NavigationManager.cs
 * This class is responsible for the navigation mechanism between WPF controls
 * **************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using FluidKit.Controls;
using SharePointExplorer.UserControls;

namespace SharePointExplorer.Classes
{
    public class NavigationManager
    {
        #region Declaration

        App CurrentApplication = (App)Application.Current;

        #endregion

        #region Constructor

        public NavigationManager()
        {
            //CurrentApplication.controlStack.Push("SharePointLocator");
        }

        #endregion

        #region Methods

        /// <summary>
        /// Loads up the first screen - SharepointLocator
        /// </summary>
        public void LoadFirstScreen()
        {
            SharePointLocator locator = new SharePointLocator();
            CurrentApplication.MainWindowInstance.CurrentPanel.Children.Clear();
            CurrentApplication.MainWindowInstance.CurrentPanel.Children.Add(locator);  
        }



        /// <summary>
        /// Navigate from one user control to another
        /// </summary>
        /// <param name="fromContent">Source User Control</param>
        /// <param name="toContent">Target User Control</param>
        /// <param name="direction">Slide Animation Direction</param>
        public void NavigateContent(UserControl fromContent, UserControl toContent, Direction direction)
        {
            CurrentApplication.controlStack.Push(toContent.Tag.ToString());
            CurrentApplication.MainWindowInstance.NextPanel.Children.Clear();
            if(CurrentApplication.MainWindowInstance.CurrentPanel.Children.Contains(toContent))
                CurrentApplication.MainWindowInstance.CurrentPanel.Children.Clear();
            CurrentApplication.MainWindowInstance.NextPanel.Children.Add(toContent);
            CurrentApplication.MainWindowInstance.TransitionContainer.Transition = new SlideTransition(direction);
            CurrentApplication.MainWindowInstance.CurrentPanel.Children.Clear();
            CurrentApplication.MainWindowInstance.CurrentPanel.Children.Add(fromContent);
            CurrentApplication.MainWindowInstance.TransitionContainer.ApplyTransition(
            CurrentApplication.MainWindowInstance.CurrentPanel, 
            CurrentApplication.MainWindowInstance.NextPanel);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="currentContent"></param>
        public void NavigateBack(UserControl currentContent)
        {
            CurrentApplication.controlStack.Pop();
            string toContent = CurrentApplication.controlStack.Pop();

            switch (toContent)
            {
                case "Dashboard":
                    NavigateContent(currentContent, new Dashboard(), Direction.LeftToRight);
                    break;

                case "DashboardItem":
                    NavigateContent(currentContent, new DashboardItem(), Direction.LeftToRight);
                    break;

                case "DashboardSubItems":
                    NavigateContent(currentContent, new DashboardSubItems(), Direction.LeftToRight);
                    break;

                case "TextReader":
                    NavigateContent(currentContent, new TextReader(), Direction.LeftToRight);
                    break;

            }

        }

        #endregion

    }
}
